﻿#ifndef FFWEBSOCKETSIGNALCLIENT_H
#define FFWEBSOCKETSIGNALCLIENT_H
#include"ffwebsocket.h"

namespace xrtc {
    class IXRTCVideoSource;
}
struct FFWebSocketSignalObserver {
    virtual void handleRemoteNewPeer(json const jMsg) = 0;
    virtual void handleResponseJoin(json const jMsg) = 0;
    virtual void handleRemotePeerLeave(json const jMsg) = 0;
    virtual void handleRemoteOffer(json const jMsg) = 0;
    virtual void handleRemoteAnswer(json const jMsg) = 0;
    virtual void handleRemoteCandidate(json const jMsg) = 0;
};

class FFWebSocketSignalClient : public FFWebSocket
{
public:
    FFWebSocketSignalClient(FFWebSocketSignalObserver* callback_);
    virtual ~FFWebSocketSignalClient();

    void sendOffer(std::string const offer, std::string remoteUid);
    void sendAnswer(std::string const answer, std::string remoteUid);
    void sendCandidate(std::string const candidate, std::string remoteUid);

protected:
    // 纯虚函数回调接口
    virtual void on_open(websocketpp::connection_hdl hdl) override;
    virtual void on_close(websocketpp::connection_hdl hdl) override;
    virtual void on_message(websocketpp::connection_hdl hdl, client::message_ptr msg) override;
    virtual void on_fail(websocketpp::connection_hdl hdl) override;

private:
    FFWebSocketSignalObserver* callback = nullptr;
    std::string remoteUid;
    std::string uid;
    std::string roomId;
};

#endif // FFWEBSOCKETSIGNALCLIENT_H
